package com.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.web.entity.RecognitionHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface RecognitionHistoryMapper extends BaseMapper<RecognitionHistory> {

    @Select("SELECT " +
            "COUNT(*) as totalCount, " +
            "SUM(CASE WHEN type IN ('disease', 'pest') THEN 1 ELSE 0 END) as diseaseCount, " +
            "COUNT(DISTINCT DATE(create_time)) as days " +
            "FROM recognition_history " +
            "WHERE user_id = #{userId} AND deleted = 0")
    Map<String, Object> getUserStats(Long userId);
}

